package jp.sample;

import jp.sample.VerticalGallery.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class MainActivity extends Activity implements VerticalGalleryAdapterView.OnItemSelectedListener {

	private Integer[] mImageIds = { R.drawable.fwhyj, R.drawable.jctq, R.drawable.jgl2, R.drawable.jlns, R.drawable.jtmdt, R.drawable.ls2, R.drawable.sdlgl };

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.main);

		VerticalGallery gallery = (VerticalGallery) findViewById(R.id.gallery);
		gallery.setAdapter(new ImageAdapter(this));
		gallery.setOnItemSelectedListener(this);
		gallery.setGravity(Gravity.CENTER_HORIZONTAL);
	}

	public void onItemSelected(VerticalGalleryAdapterView parent, View v, int position, long id) {
	}

	public void onNothingSelected(VerticalGalleryAdapterView parent) {
	}

	private class ImageAdapter extends BaseAdapter {
		private Context mContext;

		public ImageAdapter(Context c) {
			mContext = c;
		}

		public int getCount() {
			return mImageIds.length;
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView i = new ImageView(mContext);

			i.setImageResource(mImageIds[position]);
			i.setAdjustViewBounds(true);
			i.setLayoutParams(new VerticalGallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			return i;
		}
	}

}
